home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / Xaw / xcommand2.c < prev    next >
C/C++ Source or Header  |  1991-01-22  |  3KB  |  110 lines

  1. /*
  2.  * This an example of how to use the Command widget.
  3.  *
  4.  * User events handled through application action routines.
  5.  *
  6.  * November 14, 1989 - Chris D. Peterson 
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <X11/Intrinsic.h>
  11. #include <X11/StringDefs.h>    /* Get standard string definations. */
  12.  
  13. #include <X11/Xaw/Command.h>    
  14. #include <X11/Xaw/Cardinals.h>    
  15.  
  16. static void Syntax();
  17. static void SelectAction();
  18.  
  19. /*
  20.  * NOTE:   \\n is required because the C compiler throws one of them away.
  21.  */
  22.  
  23. String fallback_resources[] = { 
  24.     "*Command.Label:            Click any mouse button here",
  25.     "*Command.Translations:     #override \\n\
  26.           <BtnDown>:             set() \\n\
  27.           <BtnDown>,<BtnUp>:     SelectAction() reset()",
  28.     NULL,
  29. };
  30.  
  31. /*
  32.  * This is a list of string to action bindings, that is used by the
  33.  * Toolkit to bind an action name in a translation table to a function.
  34.  * Use XtAppAddActions() to register this table on your application context.
  35.  */
  36.  
  37. XtActionsRec actions[] = {
  38.   {"SelectAction",          (XtActionProc) SelectAction},
  39. };
  40.  
  41. static XrmOptionDescRec options[] = {
  42. {"-label",    "*Command.label",    XrmoptionSepArg,    NULL}
  43. };
  44.  
  45. main(argc, argv)
  46. int argc;
  47. char **argv;
  48. {
  49.     XtAppContext app_con;
  50.     Widget toplevel, command;
  51.  
  52.     toplevel = XtAppInitialize(&app_con, "Xcommand2",
  53.                    options, XtNumber(options),
  54.                    &argc, argv, fallback_resources,
  55.                    NULL, ZERO);
  56.  
  57.     /*
  58.      * Add string to function bindings for out application actions.
  59.      */
  60.  
  61.     XtAppAddActions(app_con, actions, XtNumber(actions));
  62.  
  63.     if (argc != 1)        
  64.     Syntax(app_con, argv[0]);
  65.  
  66.     command = XtCreateManagedWidget("command", commandWidgetClass, toplevel,
  67.                     NULL, ZERO);
  68.  
  69.     XtRealizeWidget(toplevel);
  70.     XtAppMainLoop(app_con);
  71. }
  72.  
  73. /*    Function Name: SelectAction
  74.  *    Description: This function prints the button number to stdout.
  75.  *    Arguments: w - ** UNUSED **
  76.  *                 event - the event that caused this action.
  77.  *                 params, num_params - ** NOT USED **
  78.  *    Returns: none
  79.  */
  80.  
  81. static void
  82. SelectAction(w, event, params, num_params)
  83. Widget w;
  84. XEvent * event;
  85. String * params;
  86. Cardinal * num_params;
  87. {
  88.     if (event->type == ButtonRelease) 
  89.     fprintf(stdout, "Button %d Selected.\n", (int) event->xbutton.button);
  90.     else
  91.     fprintf(stdout, "Unknown Event occured.\n");
  92. }
  93.  
  94. /*    Function Name: Syntax
  95.  *    Description: Prints a the calling syntax for this function to stdout.
  96.  *    Arguments: app_con - the application context.
  97.  *                 call - the name of the application.
  98.  *    Returns: none - exits tho.
  99.  */
  100.  
  101. static void 
  102. Syntax(app_con, call)
  103. XtAppContext app_con;
  104. char *call;
  105. {
  106.     XtDestroyApplicationContext(app_con);
  107.     fprintf( stderr, "Usage: %s [-label <label name>]\n", call);
  108.     exit(1);
  109. }
  110.